package com.class04.base;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2024/1/5 15:16
 */
public class TestSet {
    private Jedis jedis = new Jedis("127.0.0.1", 6379);

    @Test
    public void test() {
//        清空当前库的数据
        jedis.flushDB();
        jedis.sadd("myset", "a", "b", "c", "d", "e");
        jedis.sadd("set", "a", "b", "c", "d");
        Set<String> myset = jedis.smembers("myset");
        myset.stream().forEach(System.out::println);

    }
    @Test
    public void test1() {
//        1	SADD key member1 [member2]
//向集合添加一个或多个成员
//2	SCARD key
//获取集合的成员数
//        System.out.println(jedis.scard("myset"));
//3	SDIFF key1 [key2]
//返回第一个集合与其他集合之间的差异。
//        System.out.println(jedis.sdiff("myset", "set"));
//4	SDIFFSTORE destination key1 [key2]
//返回给定所有集合的差集并存储在 destination 中
//        System.out.println(jedis.sdiffstore("set1", "myset", "set"));
//        jedis.smembers("set1").stream().forEach(System.out::println);
//5	SINTER key1 [key2]
//返回给定所有集合的交集
//        System.out.println(jedis.sinter("myset", "set"));
//6	SINTERSTORE destination key1 [key2]
//返回给定所有集合的交集并存储在 destination 中
//7	SISMEMBER key member
//判断 member 元素是否是集合 key 的成员
//        System.out.println(jedis.sismember("myset", "a"));
//8	SMEMBERS key
//返回集合中的所有成员
//9	SMOVE source destination member
//将 member 元素从 source 集合移动到 destination 集合
//        System.out.println(jedis.smove("myset", "set", "a"));
//        System.out.println(jedis.smembers("set"));
//10	SPOP key
//移除并返回集合中的一个随机元素
//        System.out.println(jedis.spop("myset"));
//11	SRANDMEMBER key [count]
//返回集合中一个或多个随机数
//        System.out.println(jedis.srandmember("myset",2));
//12	SREM key member1 [member2]
//移除集合中一个或多个成员
//        System.out.println(jedis.srem("myset", "c"));
//        System.out.println(jedis.smembers("myset"));
//13	SUNION key1 [key2]
//返回所有给定集合的并集
//        System.out.println(jedis.sunion("myset", "set"));
//14	SUNIONSTORE destination key1 [key2]
//所有给定集合的并集存储在 destination 集合中
//        System.out.println(jedis.sunionstore("set2", "myset", "set"));
        jedis.smembers("set2").stream().forEach(System.out::println);
//15	SSCAN key cursor [MATCH pattern] [COUNT count]
//迭代集合中的元素

    }

}
